import java.util.Timer;
import java.util.TimerTask;

public class Demo32 {
    public static void main(String[] args) throws InterruptedException {
        //执行任务的时候加上定时器功能
        //首先创建一个Timer类的实例
        Timer timer=new Timer();
        //通过实例去调用schedule方法
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer3000");
            }
        },3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer2000");
            }
        },2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer1000");
            }
        },1000);
        Thread.sleep(4000);
        timer.cancel();
    }
}
